var Md5 = require('../../utils/md5.js');
var timeSecond = Math.floor(Date.now() * 0.001);  //获取时间戳: 
var SignInfoData = Md5.hexMD5(timeSecond + 'nativetalk')//md5加密;
var httpFile = 'http://file.waijiaojun.com/';
const app = getApp();
var httpNativetalk = app.globalData.httpNativetalk;
var httpWeike = app.globalData.httpWeike;
Page({
  data: {
    imgUrl: 'http://file.waijiaojun.com/waijiaojun/icon',
  },
  onLoad: function (e) {
    wx.getUserInfo({
      success: res => {
        app.globalData.userInfo = res.userInfo
        this.setData({
          userInfo: res.userInfo,
        })
      }
    });
    if (app.globalData.phoneNum !== null) {
      // console.log(true)
    } else {
      // console.log(false)
    };
  },
  onShow: function () {
    var that = this;
    wx.login({
      success: res => {
        // console.log(res.code);
        if (res.code !== '') {
          wx.request({
            url: httpWeike + '/wechatSmallProgram/getTokenByCode?code=' + res.code,
            data: {},
            header: {
              "Timestamp": timeSecond,
              "SignInfo": SignInfoData,
              "content-Type": "application/json",
              "client_type": "3",
              "version": 15,
            },
            method: 'GET',
            success: function (res) {
              if (res.data.obj.exist == 1) {
                app.globalData.token = res.data.obj.token;
                that.setData({
                  exist: res.data.obj.exist,
                  phone: res.data.obj.phone,
                })
              }
              // console.log(app.globalData.token);
              // console.log(res);
            },
            fail: function (res) { },
            complete: function (res) { },
          })
        }
      }
    });
    that.onLoad();
    wx.showShareMenu({
      withShareTicket: true,
    })
  },
  bingTelFun: function () {
    wx.navigateTo({
      url: '/pages/bindPhone/bindPhone',
    })
  },
  myWalletFun: function () {
    if (app.globalData.token == null) {
      wx.navigateTo({
        url: '/pages/bindPhone/bindPhone',
      })
    }
    if (app.globalData.token !== null) {
      wx.navigateTo({
        url: '/pages/myWallet/myWallet',
      })
    }


  },
  myAppoinFun: function () {
    wx.navigateTo({
      url: '/pages/myAppoint/myAppoint',
    })
  },
  myClassFun: function () {
    if (app.globalData.token == null) {
      wx.navigateTo({
        url: '/pages/bindPhone/bindPhone',
      })
    }
    if (app.globalData.token !== null) {
      wx.navigateTo({
        url: '/pages/myClass/myClass',
      })
    }

  },
  mySystemClassFun: function () {
    if (app.globalData.token == null) {
      wx.navigateTo({
        url: '/pages/bindPhone/bindPhone',
      })
    }
    if (app.globalData.token !== null) {
      wx.navigateTo({
        url: '/pages/mySystemClass/mySystemClass',
      })
    }

  }
})